Repository navigation
Conversation
…dit (#153) `janus serve` had one shared `JANUS_API_TOKEN`: it could not say who called, could not stop one caller from spending every other caller's budget, and wrote nothing when it refused. `--team-tokens FILE` now maps each caller to a name, a `read`/`write`/`admin` scope and a per-minute quota; `admin` implies the other two. Only sha256(token) is kept, each token gets its own sliding window (injected clock, no sleeps), and refusals answer 401 for missing, malformed and unknown tokens alike so a caller cannot enumerate them, 403 with the required scope in `WWW-Authenticate`, or 429 with a positive `Retry-After`. `--audit-log FILE` appends one JSON line per refusal with the first eight hex characters of the token hash, the route and the reason — never the token. An empty or malformed table raises at startup, and passing both the legacy token and a team table is an error, so the server fails closed instead of guessing.
|
claim: Janus Reviewer 1 at e7690b2 Written-by: Janus Reviewer 1 |
|
Seat assignment — T1, one seat.
Scope to read: Two things I want named in the verdict, in addition to the usual mechanical floor:
Do not review your own work; author is HugoXK, reviewer identity HugoXK-bot. Written-by: Janus Lead |
|
claim: Janus Reviewer 3 at e7690b2
Reading Written-by: Janus Reviewer 3 |
HugoXK-bot
left a comment
There was a problem hiding this comment.
Verdict: REQUEST_CHANGES at e7690b2
Reviewer: Janus Reviewer 3
Seat: 1 of 1
Tier: T1
Binding-head: e7690b2
Independent: 1/1
Diff review: one commit over five files — new core/janus/mcp/team_auth.py (330), core/janus/server.py (+60/−6), core/janus/cli.py (+24/−1), docs/MCP.md (+23), tests/test_team_auth.py (236). The 429 path, the audit line and the fail-closed startup are correct; the one blocking item is a silent config collision that defeats per-caller identity, the promise this module exists to make.
Findings.
- BLOCKING
core/janus/mcp/team_auth.py:240-244:from_configbuildstokens[raw] = TokenRecord(...)keyed by the raw secret, so two token ids that share one secret silently collapse to the last entry. The duplicate guard in__init__atcore/janus/mcp/team_auth.py:183-187("duplicate token … each caller needs its own") is unreachable through the only path the CLI uses, because the dict has already deduplicated the secret. Reproduced with the documented config shape:{"tokens": {"alice": {"token": "same", "scopes": ["read"]}, "bob": {"token": "same", "scopes": ["admin"], "rate_limit_per_min": 5}}}→TeamAuth.from_config(...).authorize({"Authorization": "Bearer same"}, required="admin").token_id == "bob", one record on file, no exception. Alice is gone: her calls are attributed to bob, her token now carries bob's scopes, and the two "independent" budgets are one deque (core/janus/mcp/team_auth.py:190-193,:275). The same collision happens through the public constructor with two different secrets that declare the sametoken_id(self._windowskeeps one deque). Fix: infrom_config, before assigning, check whether the raw secret is already present and raiseValueError(f"tokens {first_id!r} and {token_id!r} share one token"); keep the digest check in__init__as the backstop, and key_windowsby digest rather thantoken_idor reject duplicate ids. One test in the config-validation test covers it. core/janus/server.py:165-166: the server always passesrequired="read". The surface is GET-only (do_HEADanswersAllow: GETatcore/janus/server.py:214-220), sowriteandadminare never demanded by any route: a read-only token reaches every/api/*route, a["write"]-only token is refused everywhere, andadminis indistinguishable fromread. That is inside #153's letter (the AC only requires that an insufficient scope gets 403 with the scope named, whichtests/test_team_auth.py:110-119proves at the module level), butdocs/MCP.mdshould say plainly that read is the only enforced scope today, or the server should pass a per-method required scope when a writing route exists. Not blocking.tests/test_team_auth.py:139-147: AC "并发两令牌互不影响" and the test requirement "并发隔离" are tested sequentially. The window update is underself._lock(core/janus/mcp/team_auth.py:283-285), so the behaviour is probably fine, but the stated test does not exercise it. Add one thread test: two tokens, one thread each, N calls each, assert each hits its own 429 count. Not blocking.core/janus/server.py:169-173: the 401 body carriesexc.reason, so/api/*answers distinguishmissing_token,malformed_tokenandunknown_tokeninbody["error"]/body["message"], while the test attests/test_team_auth.py:64is named "one indistinct 401" and #153's table says malformed/missing "不泄漏原因细节". Statuses are identical, so enumeration by status is blocked; the body still names the cause. Send oneunauthorizedbody for 401 and keep the reason in the audit line only. Not blocking.core/janus/cli.py:640-668: two operator-path defects.--audit-logis accepted without--team-tokensand then silently dropped (audit_logis only read inside theteam_auth is not Nonebranch), so an operator can believe denials are logged while they are not. AndTeamAuth.from_configraises a rawValueErrorthat Typer does not wrap, sojanus serve --team-tokens bad.jsonexits through a rich traceback (ValueError: token 'ops': unknown scope(s): root) instead of a one-lineBadParameter, unlike the file/JSON errors two lines above atcore/janus/cli.py:657-665. Both fail closed; both are UX, not security. Not blocking.core/janus/server.py:137,178:principalis assigned but never read anywhere in the diff, so "for handlers and audit lines" is still aspiration. Harmless today; either consume it (a response header or an audit of allowed calls) or drop the attribute. Not blocking.
Verified on the 429 path (the Lead's second ask): with limit 2 and an injected clock, the third call is 429 with Retry-After values 60, 60, 30, 10, 1, 1 after advancing 0, 0.4, 29.6, 20, 9.9, 0.01 seconds — always a positive integer, non-increasing as the window slides, and recovery happens once the oldest entry leaves. The audit line for an unknown token is {"at": …, "event": "denied", "reason": "unknown_token", "route": "/", "status": 401, "token_hash_prefix": "99dc2201"}: eight hex characters of sha256, no token, and the same line shape is written per refusal (tests/test_team_auth.py:204-212 asserts the file case).
Verified on the Lead's first ask (scope beyond #153): the diff implements Fixes #153 and nothing else. The extra docs/MCP.md section and the two CLI flags are the operational surface #153 needs ("令牌由运维以文件/环境注入"), not another card. #150 (charts/drill-down), #154 (PWA brief) and #157 (tracing/SLO) are untouched — none of their files appear. So Fixes #153 is the correct and only closure, once this blocking item is fixed.
Red-first: with tests/test_team_auth.py from this head placed in the base tree (199acbe), collection fails on the missing core/janus/mcp/team_auth.py and the old make_server(team_auth=…); it is red before the change by construction, not by a mutation.
Risk: low. The new module is opt-in behind --team-tokens; JANUS_API_TOKEN and the no-token default are unchanged in behaviour, and no route semantics changed. The blocking defect is startup-time config handling — it fails open toward the last entry, silently, rather than exposing a remote attack surface.
Ran: PYTHONPATH=/tmp/r3j339/core /tmp/r3j332/.venv/bin/python -m pytest tests/test_team_auth.py tests/test_server.py -o addopts="" -q -> 24 passed in 12.53s; ... -m ruff check core/janus/mcp/team_auth.py core/janus/server.py core/janus/cli.py tests/test_team_auth.py -> All checks passed!; ... -m mypy core/janus/mcp/team_auth.py core/janus/server.py --ignore-missing-imports -> Success: no issues found in 2 source files; /tmp/probe339.py -> DUPLICATE_RAW_TOKEN: accepted, principal = bob | tokens on record: 1, slide +0/+0.4/+29.6/+20/+9.9/+0.01 -> Retry-After 60/60/30/10/1/1, AUDIT_HAS_FULL: False; base-tree run of the new tests -> ERROR: 1 error during collection.
Not run: full uv run pytest -q, uv build, TLS/remote deployment, concurrent-load soak (the AC concurrency test is missing, see above).
Written-by: Janus Reviewer 3
|
Security: e7690b2 — BLOCK Security: BLOCK at e7690b2 Scope: S1 — pre-authentication unbounded growth: a refusal flood is never bounded. So 20 000 unauthenticated requests buy 20 000 live dicts (~413 B each, ~8.3 MB measured) that are never released for the life of the process. With Why this is reachable without a credential and without CORS permission: the request is executed server-side and audited before any origin check. Clear condition: bound the refusal record — a fixed-size in-memory ring (drop-oldest, e.g. 1 000) plus a size/rotation cap on the JSONL — so one refusal costs O(1) and bounded storage; the audit must never be the growth path. S2 — unknown-token attempts are never throttled, which is what lets S1 run at line rate. Two consequences: the S1 flood is unbounded in rate as well as size, and online guessing against a token table is unbounded — which matters because there is no minimum token strength: Clear condition: apply a failure budget before token lookup — a global and/or per-client-IP counter shared by all S3 — the denial line is a verifier for a valid token. Anyone who can read the audit log — and with Clear condition: never publish a verifier of a live secret — HMAC the recorded value with a per-install salt kept outside the log, or record only S4 — the scoped model has no enforcement point, so Clear condition (can be a follow-up, not this merge): an explicit route→scope table with default-deny for an unmapped S5 — One integrity caveat about this veto itself. What would clear this veto. S1 and S2 fixed in one follow-up commit on this branch (bounded audit storage; pre-lookup failure budget; minimum token length), S3 fixed by dropping the live-secret verifier and setting the audit file to
|
…#153) The review's blocking item was real: `from_config` keyed its table by the raw secret, so two token ids sharing one secret collapsed to the last entry before `__init__` could see the collision. Alice's calls were attributed to Bob and her token carried Bob's scopes. `from_config` now refuses `tokens 'alice' and 'bob' share one token`, `__init__` refuses a duplicate `token_id`, and the rate-limit windows are keyed by digest instead of by name, so two records can never share one budget. Also from the review: 401 answers carry only `unauthorized` (the detail stays in the audit line), `--audit-log` without `--team-tokens` is a usage error rather than a silently dropped flag, a bad token table is a one-line `BadParameter` instead of a traceback, the authorized caller is sent back in `X-Janus-Principal`, and `docs/MCP.md` says plainly that `read` is the only scope any current route demands.
|
Fix round at head BLOCKING — shared secret collapsed two callers. Confirmed exactly as you reproduced it: Non-blocking, all taken
Local at Written-by: Janus Dev Lead. |
|
CI caught my own test at Fix at head Written-by: Janus Dev Lead. |
|
Seat assignment — T1, one seat, second round on the new head.
This head answers your What I want settled, in order:
Written-by: Janus Lead |
Summary
janus servehad one sharedJANUS_API_TOKEN. It could not say who called, could not stop one caller from spending every other caller's budget, and recorded nothing when it refused. This adds the smallest honest team mode on the same HTTP surface, with no change to route semantics.Design note (5 lines)
core/janus/mcp/team_auth.pyholds a token table (sha256 only), scope check, per-token sliding window with an injectable clock, and a JSONL denial audit;server.pyasks it for aPrincipalbefore the existing/api/*dispatch,--team-tokens/--audit-logwire it from the CLI.auth.py— rejected because that module's tokens come fromJANUS_MCP_TOKENSand scope the MCP tools; sharing it would tie the HTTP panel's quotas to MCP config and make two surfaces fail together.--team-tokensis opt-in and the legacyJANUS_API_TOKENpath is unchanged, so no data migration is involved.Fixes #153.Acceptance criteria
missing_token/malformed_token/unknown_token) so a caller cannot enumerate valid tokens.WWW-Authenticate: Bearer error="insufficient_scope", scope="read";adminsatisfiesread,writeandadmin(asserted both ways: read token asking foradminis 403).N+1overrate_limit_per_min→ 429 with a positiveRetry-After; requestNis still 200; after the window slides, the token is accepted again (Retry-Aftershrinks from 60 to 30 to accepted).token_hash_prefix(first 8 hex),routeandreason; the test asserts the file never contains the full token and every line carries a prefix.readerdoes not touchwriter/admin.ValueErrornaming the token id; an empty table refuses to start;make_server(token=…, team_auth=…)raises instead of picking one.Evidence (
e7690b2014378077ef12baeca997082ec5e3b3e5, base199acbe)Ran: PYTHONPATH=core .venv/bin/python -m pytest tests/test_team_auth.py tests/test_server.py -o addopts="" -q→24 passed in 11.19s; withtests/test_mcp_scoped_auth.py→71 passed in 10.13s.Ran: .venv/bin/ruff check .→All checks passed!Ran: PYTHONPATH=core .venv/bin/python -m janus schema check→schema ok: schemas/janus.schema.json;janus demo→ ok.Ran: .venv/bin/mypy core/janus/mcp/team_auth.py core/janus/cli.py→ clean (the only remaining local error ispandasstubs missing from this machine,server.py:75, an environment gap CI's typecheck does not have).Red first: the two server-integration tests run against the old
server.pyfail withTypeError: make_server() got an unexpected keyword argument 'team_auth'(2 failed, 6 passed); with the new module all 8 pass.Packaging note (PB-31.4)
One card, not three: the other
area:interfaceready cards are#150(dsh-plugin chart layer) and#22(Ed25519 share bundles) — different file surfaces, and#22is T2 needing its own seats; a hard bundle would pass 800 lines and mix two threat models.#299is already in#337. Say the word and I will stack the next interface slice on this branch.Risk
T1: a config/auth change on the HTTP boundary. The legacy single-token path is untouched and still covered by
test_token_protects_api_but_not_health; team mode is opt-in, fails closed when misconfigured, and never logs a token.Written-by: Janus Dev Lead.